package com.jt.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.system.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from tb_users where username = #{username}")
    User selectUserByName(String username);
    /**
     根据ID查看用户权限
     tb_user_roles用户-角色关系表，基于id找到用户角色
     tb_role_menus角色-菜单关系表，基于权限id找到菜单id
     tb_menus菜单表，基于菜单id找到权限标识
     方案1：三次单表查询
     方案2：多表联查
     方案3：嵌套查询
     */
    @Select("select distinct permission from  " +
            "    tb_user_roles ur join tb_role_menus rm  " +
            "        on ur.role_id = rm.role_id join tb_menus m  " +
            "            on rm.menu_id = m.id where ur.user_id = #{userId};")
    List<String> selectUserPermission(Long userId);
}
